<?php
/**
 *
 */
class DigUi_Plugin_Hotkeys extends Zend_Controller_Plugin_Abstract
{

    /**
     *
     * @param Zend_Controller_Request_Abstract $request
     */
    public function postDispatch(Zend_Controller_Request_Abstract $request)
    {
        $view = Zend_Layout::getMvcInstance()->getView();
        $hotkeys = DigUi_Service_Hotkeys::getHotkeys();
        if($hotkeys) {
            foreach ($hotkeys as $key => $path) {
                $jquery = sprintf("$(document).bind('keydown', '%s', function(){
                    $.dig.ui.disable();
                    $.post('%s', null, function(response){
                        $.dig.ui.message.add(response.message, response.type);
                        $.dig.ui.enable();
                    }, 'json');
                    return false;
                });", $key, $path);
                $view->jQuery()->addOnLoad($jquery);
            }
        }
    }
}
?>